package com.example.user_service.user_contorller.FService.impl;

import com.example.user_service.user_contorller.FDao.AddressMapper;
import com.example.user_service.user_contorller.FService.AddressService;
import com.example.user_service.vo.AddressVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AddressServiceimpl implements AddressService {

    @Autowired
    AddressMapper addressMapper;



    @Override
    public List<AddressVO> selectmyaddress(int userid,int status) {
        return addressMapper.selectmyaddress(userid,status);
    }

    @Override
    public int addaddress(AddressVO addressVO) {
        if (addressVO.getStatus()==1){
            addressMapper.cleanstatus(addressVO.getUser_id());
            return addressMapper.addaddress(addressVO);
        }else{
            return addressMapper.addaddress(addressVO);
        }
    }

    @Override
    public int updateaddress(AddressVO addressVO) {
        if (addressVO.getStatus()==1){
            addressMapper.cleanstatus(addressVO.getUser_id());
            return addressMapper.updateaddress(addressVO);
        }else{
            return addressMapper.updateaddress(addressVO);
        }
    }

    @Override
    public int changedefault(int addressid,int user_id) {
        addressMapper.cleanstatus(user_id);
        return addressMapper.changedefault(addressid,user_id);
    }

    @Override
    public int deleltadd(int addressid, int user_id) {
        return addressMapper.deleltadd(addressid,user_id);
    }

    @Override
    public AddressVO selectaddressbyid(int addressid) {
        return addressMapper.selectaddressbyid(addressid);
    }
}
